//
//  LGMainTabBarController.swift
//  01-Weibo项目练习-1
//
//  Created by 李李刚 on 16/3/2.
//  Copyright © 2016年 李李刚. All rights reserved.
//

import UIKit


class LGMainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //使用自定义的tabBar
        let lgTabBar: LGTabBar = LGTabBar()
        
//        lgTabBar.backgroundImage = UIImage(named: "tabbar_background")
        
        //因为系统的tabbar是readonly受保护,所以使用kvc的方式赋值
        setValue(lgTabBar, forKeyPath: "tabBar")
        
        
        addChildViewController(LGHomeViewController(), imageName: "tabbar_home", title: "首页")
        
        addChildViewController(LGMessageViewController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(LGDiscoverViewController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(LGProfileViewController(), imageName: "tabbar_profile", title: "我")
        
        
        
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    private func addChildViewController(childController: UIViewController , imageName: String , title:String ) {
        
//        childController.title = title
        //设置底部文字
        childController.title = title
        
        //设置字体颜色
        let attributes = [NSForegroundColorAttributeName:UIColor.orangeColor()]
        
        childController.tabBarItem.setTitleTextAttributes(attributes, forState: .Selected)
        
        //控制器背景颜色
//        childController.view.backgroundColor = UIColor.whiteColor()
        
//        childController.view.backgroundColor = UIColor.redColor()
        

        //设置tabbaritem的背景图片
        childController.tabBarItem.image = UIImage(named: imageName)?.imageWithRenderingMode(.AlwaysOriginal)
        
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        let nav = UINavigationController(rootViewController: childController)
        
        addChildViewController(nav)
//        addChildViewController(UINavigationController(rootViewController: childController))
        
        
    }
    
    

}
